const query = require("../mysql/query"); //引入异步查询方法


//用户权限查询
var userAuth = async (ctx, next) => {
  let userName = ctx.request.body.userName;
  var  Sql = `SELECT * FROM login WHERE user_name='${userName}'`
  let res = await query(Sql)
  if(res.length>0){
    ctx.body = {
      data:res,
      code:'200',
      msg:'成功'
    }
  }else{
    ctx.body = {
      code:'100',
      msg:'不存在该用户'
    }
  }
  
};

//用户权限保存
var userAuthSave = async (ctx, next) => {
  let userName = ctx.request.body.userName;
  let auth = ctx.request.body.auth;
  var Sql = `UPDATE login SET auth='${auth}' WHERE user_name='${userName}'`
  await query(Sql)
  ctx.body = {
      code:'200',
      msg:'成功'
    }
};


module.exports = {
  'POST /userAuth': userAuth,
  'POST /userAuthSave':userAuthSave
};